import { getDict } from '@/utils/dictionary'
import { createReqMessage } from '@/api/req_msg'
export default {
  data() {
    return {
      page: 1,
      total: 10,
      pageSize: 10,
      tableData: [],
      searchInfo: {}
    }
  },
  methods: {
    filterDict(value, type) {
      const rowLabel = this[type + 'Options'] && this[type + 'Options'].filter(item => item.value === value)
      return rowLabel && rowLabel[0] && rowLabel[0].label
    },
    async getDict(type) {
      const dicts = await getDict(type)
      this[type + 'Options'] = dicts
      return dicts
    },
    async sendModelRequest(reqName, requestID) {
      // reqName:请求名称 对应路由名称;
      // requestID:请求ID 对应数据库表id
      // reqStatae:请求状态修改为：请求中
      const reqState = 1
      const data = {
        requestID,
        reqName,
        reqState
      }
      const res = await createReqMessage(data)
      if (res.code === 0) {
        this.$message({
          type: 'success',
          message: '操作成功'
        })
        this.$bus.$emit('reload')
      }
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.getTableData()
    },
    handleCurrentChange(val) {
      this.page = val
      this.getTableData()
    },
    async getTableData(page = this.page, pageSize = this.pageSize) {
      const table = await this.listApi({ page, pageSize, ...this.searchInfo })
      if (table.code === 0) {
        this.tableData = table.data.list
        this.total = table.data.total
        this.page = table.data.page
        this.pageSize = table.data.pageSize
      }
    }
  }
}
